home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_08
/
9n08055b
< prev
next >
Wrap
Text File
|
1991-06-19
|
1KB
|
53 lines
/***************** Listing 2 *************************
Bilinear Interpolation
double bilinear(image, x, y)
float *image, x, y;
image: pointer to the four values of grid i.e.
a 2 x 2 array ( image[2][2] )
x : sample coordinate
y : line coordinate
p
|------------->
image(0,0) image(0,1)
- *-------------------*
| | |
q V | o |
| (y,x) | y = line
| | x = sample
| |
| |
*-------------------*
image(1,0) image(1,1)
If point "o" falls on upper left corner, then
return image(0,0). The point should never fall on
any of the other corners because the calling
program will ensure against this according to the
filling sequence of the array image[2][2].
******************************************************
#include <stdio.h>
double bilinear(image, x, y)
float *image, x, y;
{
register i;
float p, q;
double val = 0.0;
p = x - (int) x;
q = y - (int) y;
if( (p == 0.0) && (q == 0.0) )
return( (double) *image ); /* upper left */
val = (p*q* *image++) + (q*(1-p)* *image++) + \
(p*(1-q)* *image++) + ((1-p)*(1-q)* *image);
return( val );
}